package com.fiberhome.ztelauncher.core.page.model;

import android.text.TextUtils;

import com.fiberhome.ztelauncher.core.page.type.TypeFactory;
import com.fiberhome.ztelauncher.xml.bean.LaunchDataPage;
import com.fiberhome.ztelauncher.xml.bean.LauncherLayout;


/**
 * Created by xc on 2018/3/27.
 * 描述：
 */

public class BaseType implements Visitable {
    private final static String IMAGE = "image";
    private final static String VIDEO = "video";
    private final static String LIST = "list";
    private final static String WIDGET = "widget";
    private final static String CUSTOM = "custom";
    private final static String ADBANNER = "adbanner";
    private final static String RECOMMEND = "recommend";
    private String pageType;

    private LauncherLayout.Element layoutElement;
    private LaunchDataPage.Element dataElement;
    private LauncherLayout.Page page;

    public BaseType(String pageType, LauncherLayout.Element layoutElement, LaunchDataPage.Element dataElement, LauncherLayout.Page page) {
        this.pageType = pageType;
        this.layoutElement = layoutElement;
        this.dataElement = dataElement;
        this.page = page;
    }

    public BaseType getType(LauncherLayout.Element layoutElement,
                            LaunchDataPage.Element dataElement, LauncherLayout.Page page) {
        if (!TextUtils.isEmpty(pageType)) {
            return new AppType(layoutElement, dataElement, page);
        }
        if (IMAGE.equals(layoutElement.type)) {
            return new ImageType(layoutElement, dataElement, page);

        } else if (VIDEO.equals(layoutElement.type)) {
            return new VideoType(layoutElement, dataElement, page);

        } else if (LIST.equals(layoutElement.type)) {
            return new ListType(layoutElement, dataElement, page);

        } else if (WIDGET.equals(layoutElement.type)) {
            return new WidgetType(layoutElement, dataElement, page);

        } else if (CUSTOM.equals(layoutElement.type)) {
            return new CustomType(layoutElement, dataElement, page);

        } else if (ADBANNER.equals(layoutElement.type)) {
            return new AdBannerType(layoutElement, dataElement, page);

        } else if (RECOMMEND.equals(layoutElement.type)) {
            return new RecommendType(layoutElement, dataElement, page);

        }

        return new ImageType(layoutElement, dataElement, page);
    }

    /**
     * get value
     *
     * @return value
     */
    public LauncherLayout.Element getLayoutElement() {
        return layoutElement;
    }

    /**
     * get value
     *
     * @return value
     */
    public LaunchDataPage.Element getDataElement() {
        return dataElement;
    }

    /**
     * get value
     *
     * @return value
     */
    public LauncherLayout.Page getPage() {
        return page;
    }

    @Override
    public int type(TypeFactory typeFactory) {
        return 0;
    }
}
